import { formatMonthTitle } from "miniprogram/miniprogram_npm/@vant/weapp/calendar/utils"
import {patch} from "@utils/http"
import { FormEvent } from "miniprogram/@types/Event"
import { tipBehavior } from "@mixin/tip"

// components/wegets/dynamic-cell/dynamic-cell.ts
Component({

  /**
   * 组件的属性列表
   */
  properties: {
    detail:{}
  },

  /**
   * 组件的初始数据
   */
  data: {

  },

  /**
   * 组件的方法列表
   */
  methods: {
    getDetail(){
      const detail=this.data.detail
      wx.navigateTo({
        url:`/pages/dynamic/comment/comment?detail=${JSON.stringify(detail)}`,
      })
    },
    async loveDynamic(e){
      const detail=this.data.detail
      const res=await patch("/dynamics/likes",{
        like:!detail.islove,
        id:detail.id
      })
      this.triggerEvent("love")
    },
    getContact(e){
      const detail=this.data.detail
      const contact=detail.contact
      const provided=detail.provided
      if(provided){
        wx.setClipboardData({
          data:contact,
          success:res=>{
            wx.showToast({
              title:"复制成功"
            })
          }
        })
      }else{
        wx.showToast({
          title:"用户不提供联系方式"
        })
      }
    },
    shareDynamic(e){
     getApp().globalData.dynamic=this.data.detail
      wx.showShareMenu({ // 是否使用带 shareTicket 的转发
        menus: ['shareAppMessage', 'shareTimeline'] // 显示的分享按钮类型
      })
    },
    preViewImage(e:FormEvent<{src:string}>){
       const {src}=e.currentTarget.dataset
       wx.previewImage({
         urls:this.data.detail.srcs,
         current:src
       })
    }
  }
})